package shanghaielectric.com.shanghaielectric;

import android.app.Application;
import android.content.Context;
import android.serialport.SerialPort;

import com.facebook.stetho.Stetho;

import org.litepal.LitePal;

import java.io.File;
import java.io.IOException;
import java.security.InvalidParameterException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import shanghaielectric.com.shanghaielectric.DBConfig.DB.DBHelper_config;
import shanghaielectric.com.shanghaielectric.DeviceConfigModel.Device.Device;
import shanghaielectric.com.shanghaielectric.DeviceConfigModel.Point.PointEnumData;

/**
 * Created by cuihanbing on 2017/11/1.
 */

public class MyApplication extends Application {
    public static MyApplication myApplication;
    private Context mContext;
    private Map<Integer, Device> devices = new HashMap<>();
    private DBHelper_config dbHelper_config;
    private List<PointEnumData> pointEnumDataList;

    @Override
    public void onCreate() {
        super.onCreate();
        LitePal.initialize(this);
        Stetho.initializeWithDefaults(this);
        myApplication = this;
        mContext = this.getApplicationContext();
//        initDBHelper_config();
    }

    private void initDBHelper_config() {
        dbHelper_config = DBHelper_config.getDBHelper_config();
    }

    public Map<Integer, Device> getDevices() {
        if (dbHelper_config == null) {
            initDBHelper_config();
            devices = dbHelper_config.getDevices();
            return devices;
        } else {
            return devices = dbHelper_config.getDevices();
        }
    }

    public List<PointEnumData> getPointEnumDataList() {
        if (dbHelper_config == null) {
            initDBHelper_config();
            pointEnumDataList = dbHelper_config.getPointEnumDataList();
            return pointEnumDataList;
        } else {
            return pointEnumDataList;
        }

    }



}
